﻿using System;
using System.Collections.Generic;
using System.IO;

using System.Xml;
using System.Linq;
using System.Text;
using Office = Microsoft.Office.Core;
using PPT = Microsoft.Office.Interop.PowerPoint;
using System.Windows.Media;
using System.Xml.Linq;

namespace An_Im
{
    /// <summary>
    /// 动画数据库部分。
    /// </summary>
    static partial class CoreManipulator
    {
        /// <summary>
        /// 行为类型->名称
        /// </summary>
        internal static Dictionary<PPT.MsoAnimType, string> typedic1;

        /// <summary>
        /// 名称->行为类型
        /// </summary>
        internal static Dictionary<string, PPT.MsoAnimType> typedic2;

        /// <summary>
        /// 动画属性->名称
        /// </summary>
        internal static Dictionary<PPT.MsoAnimProperty, string> propdic1;


        /// <summary>
        /// 名称->动画属性
        /// </summary>
        internal static Dictionary<string, PPT.MsoAnimProperty> propdic2;


        /// <summary>
        /// 动画效果，如《百叶窗》->名称
        /// </summary>
        internal static Dictionary<PPT.MsoAnimEffect, Tuple<string, string>> animtypedic1;

        /// <summary>
        /// 名称->动画效果如《百叶窗》
        /// </summary>
        internal static Dictionary<string, NativeAnimEffect> animtypedic2;


        /// <summary>
        /// 动画信息列表。
        /// </summary>
        public static List<EffectInformation> EffectInformationList { get; private set; }


        /// <summary>
        /// 标签列表，如 进入动画 = tag1。
        /// </summary>
        public static IDictionary<string, Tag> TagDictionary { get; private set; }

        /// <summary>
        /// 标签组列表，如 默认模式 = 进入、退出。
        /// </summary>
        public static IDictionary<string, TagGroup> TagGroupDictionary { get; private set; }

        /// <summary>
        /// 动画属性类型参考，动画类型，如 Property = "msoAnimX" 。
        /// </summary>
        public static IDictionary<PPT.MsoAnimProperty, string> AnimPropertyNameDictionary => propdic1;


        /// <summary>
        /// 动画属性类型参考，动画类型，如 Type = "set" 。
        /// </summary>
        public static IDictionary<PPT.MsoAnimType, string> AnimBehaviorTypeNameDictionary => typedic1;

        ///// <summary>
        ///// 自定义收藏的动画列表。
        ///// </summary>
        //public static List<EffectInformation> CustomAnimationList { get; }

        static CoreManipulator()
        {


        }

        public static void Initialize()
        {
            TagDictionary = new Dictionary<string, Tag>();
            TagGroupDictionary = new Dictionary<string, TagGroup>();
            EffectInformationList = new List<EffectInformation>();

            typedic1 = new Dictionary<PPT.MsoAnimType, string>();
            typedic2 = new Dictionary<string, PPT.MsoAnimType>();
            propdic1 = new Dictionary<PPT.MsoAnimProperty, string>();
            propdic2 = new Dictionary<string, PPT.MsoAnimProperty>();
            animtypedic1 = new Dictionary<PPT.MsoAnimEffect, Tuple<string, string>>();
            animtypedic2 = new Dictionary<string, NativeAnimEffect>();

            LoadMsoAnimTypeDic();
            LoadMsoAnimPropertyDic();
            AnimEffect.Initialize();

            if (File.Exists(SavePath))
                CustomDataBaseInitialize();
            else
                AnyiDataBaseInitialize();

        }

        private static void AnyiDataBaseInitialize()
        {
            var anyiXmlDoc = new XmlDocument();
            anyiXmlDoc.LoadXml(Properties.Resources.AnimationDataBase);

            var tags = LoadTags(anyiXmlDoc);
            foreach (var tag in tags)
            {
                if (!TagDictionary.ContainsKey(tag.Name))
                    TagDictionary.Add(tag.Name, tag);
            }

            var taggrps = LoadTagGroup(anyiXmlDoc);
            foreach (var taggrp in taggrps)
            {
                if (!TagGroupDictionary.ContainsKey(taggrp.Name))
                    TagGroupDictionary.Add(taggrp.Name, taggrp);
            }


            var artificialEffectInformation = LoadArtificialEffectInformations(anyiXmlDoc);
            var nativeEffectInformation = LoadNativeEffectInformations(anyiXmlDoc);
            var groupEffectInformation = LoadGroupEffectInformations(anyiXmlDoc);

            var effInformation = new List<EffectInformation>();
            effInformation.AddRange(artificialEffectInformation);
            effInformation.AddRange(nativeEffectInformation);
            effInformation.AddRange(groupEffectInformation);
            EffectInformationList.AddRange(effInformation);
        }

        private static void CustomDataBaseInitialize()
        {
            var defaultTag = new Tag()
            {
                NormalBackground = new SolidColorBrush(Colors.White),
                OverBackground = new SolidColorBrush(Colors.White),
                PressedBackground = new SolidColorBrush(Colors.White),
                AnimEffect = animtypedic2["自定义"],
                Icon = null,
                Name = "默认标签",
                EffectInformationList = new List<EffectInformation>()
            };
            if (!TagDictionary.ContainsKey(defaultTag.Name))
                TagDictionary.Add(defaultTag.Name, defaultTag);
            var defaultTagGroup = new TagGroup(new Tag[] { defaultTag });
            if (!TagGroupDictionary.ContainsKey("自定义模式"))
                TagGroupDictionary.Add("自定义模式", defaultTagGroup);

            var savePath = SavePath;
            if (!File.Exists(SavePath)) return;

            var customXmlDoc = new XmlDocument();
            customXmlDoc.Load(SavePath);

            var artificialEffectInformation = LoadArtificialEffectInformations(customXmlDoc);
            var nativeEffectInformation = LoadNativeEffectInformations(customXmlDoc);
            var groupEffectInformation = LoadGroupEffectInformations(customXmlDoc);

            var effInformation = new List<EffectInformation>();
            effInformation.AddRange(artificialEffectInformation);
            effInformation.AddRange(nativeEffectInformation);
            effInformation.AddRange(groupEffectInformation);
            EffectInformationList.AddRange(effInformation);

            //CustomAnimationList
        }

        private static void AddTypeDicRecord(PPT.MsoAnimType animType, string name)
        {
            typedic1.Add(animType, name);
            typedic2.Add(name, animType);
        }

        private static void AddPropDicRecord(PPT.MsoAnimProperty animType, string name)
        {
            propdic1.Add(animType, name);
            propdic2.Add(name, animType);
        }

        private static void AddAnimEffectRecord(PPT.MsoAnimEffect animType, string name)
        {
            animtypedic1.Add(animType, new Tuple<string, string>(name, name));
            animtypedic2.Add(name, new NativeAnimEffect(animType, null) { OriginName = name, ReplacedName = name });
        }

        private static void AddAnimEffectRecord(PPT.MsoAnimEffect animType, string name1, string name2)
        {
            animtypedic1.Add(animType, new Tuple<string, string>(name1, name2));
            animtypedic2.Add(name1, new NativeAnimEffect(animType, Office.MsoTriState.msoFalse) { OriginName = name1, ReplacedName = name1 });
            animtypedic2.Add(name2, new NativeAnimEffect(animType, Office.MsoTriState.msoTrue) { OriginName = name2, ReplacedName = name2 });
        }

        private static void LoadMsoAnimTypeDic()
        {

            AddTypeDicRecord(PPT.MsoAnimType.msoAnimTypeSet, "设置");
            AddTypeDicRecord(PPT.MsoAnimType.msoAnimTypeProperty, "属性");
            AddTypeDicRecord(PPT.MsoAnimType.msoAnimTypeColor, "颜色");
            AddTypeDicRecord(PPT.MsoAnimType.msoAnimTypeScale, "比例");
            AddTypeDicRecord(PPT.MsoAnimType.msoAnimTypeRotation, "旋转");
            AddTypeDicRecord(PPT.MsoAnimType.msoAnimTypeFilter, "滤镜");
            AddTypeDicRecord(PPT.MsoAnimType.msoAnimTypeMotion, "移动");

            AddTypeDicRecord(PPT.MsoAnimType.msoAnimTypeCommand, "控制");
            AddTypeDicRecord(PPT.MsoAnimType.msoAnimTypeMixed, "未知");
            AddTypeDicRecord(PPT.MsoAnimType.msoAnimTypeNone, "无定义");
        }

        private static void LoadMsoAnimPropertyDic()
        {
            AddPropDicRecord(PPT.MsoAnimProperty.msoAnimX, "X");
            AddPropDicRecord(PPT.MsoAnimProperty.msoAnimY, "Y");
            AddPropDicRecord(PPT.MsoAnimProperty.msoAnimVisibility, "可见性");
            AddPropDicRecord(PPT.MsoAnimProperty.msoAnimWidth, "宽度");
            AddPropDicRecord(PPT.MsoAnimProperty.msoAnimHeight, "高度");
            AddPropDicRecord(PPT.MsoAnimProperty.msoAnimColor, "颜色");
            AddPropDicRecord(PPT.MsoAnimProperty.msoAnimOpacity, "透明度");
            AddPropDicRecord(PPT.MsoAnimProperty.msoAnimRotation, "角度");
        }




        /// <summary>
        /// 载入标签
        /// </summary>
        private static IEnumerable<Tag> LoadTags(XmlDocument xmldoc)
        {
            var list = new List<Tag>();
            var effects = new List<ArtificialEffectInformation>();

            foreach (XmlElement tagNode in xmldoc["动画数据"]["标签定义列表"])
            {
                //<标签 名称="进入动画" 颜色1="#ecf8ee" 颜色2="#d9f1dd" 颜色3="#5bc46b" 基础动画样式="淡入" />
                var name = tagNode.GetAttribute("名称");
                var iconName = tagNode.GetAttribute("图标");
                var color1 = StringToColor(tagNode.GetAttribute("颜色1"));
                var color2 = StringToColor(tagNode.GetAttribute("颜色2"));
                var color3 = StringToColor(tagNode.GetAttribute("颜色3"));
                var style = tagNode.GetAttribute("基础动画样式");
                var animTuple = animtypedic2[style];
                var tag = new Tag();
                tag.EffectInformationList = new List<EffectInformation>();

                tag.Icon = GetImageSource(iconName);

                tag.Name = name;
                tag.NormalBackground = new SolidColorBrush(color1);
                tag.OverBackground = new SolidColorBrush(color2);
                tag.PressedBackground = new SolidColorBrush(color3);
                tag.AnimEffect = animTuple;
                list.Add(tag);
            }

            return list;
        }

        /// <summary>
        /// 载入标签组
        /// </summary>
        private static IEnumerable<TagGroup> LoadTagGroup(XmlDocument xmldoc)
        {
            var list = new List<TagGroup>();

            foreach (XmlElement tagGrpNode in xmldoc["动画数据"]["标签组列表"])
            {
                var name = tagGrpNode.GetAttribute("名称");
                var tagNames = tagGrpNode.GetAttribute("标签集合");
                var tagList = new List<Tag>();
                foreach (var tagName in tagNames.Split(','))
                {
                    var tagName2 = tagName.Trim();
                    if (TagDictionary.ContainsKey(tagName2))
                        tagList.Add(TagDictionary[tagName2]);
                }
                list.Add(new TagGroup(tagList) { Name = name });
            }
            return list;
        }


        /// <summary>
        /// 载入效果信息。
        /// </summary>
        private static IEnumerable<ArtificialEffectInformation> LoadArtificialEffectInformations(XmlDocument xmldoc)
        {

            var effects = new List<ArtificialEffectInformation>();

            var list = xmldoc["动画数据"]["动画数据列表"];
            if (list == null) return null;
            foreach (XmlElement effNode in list)
            {
                var effinfo = LoadArtificialEffectInformation(effNode);
                effects.Add(effinfo);
            }

            return effects;

        }

        private static IEnumerable<NativeEffectInformation> LoadNativeEffectInformations(XmlDocument xmldoc)
        {

            var effects = new List<NativeEffectInformation>();

            var list = xmldoc["动画数据"]["原生数据列表"];
            if (list == null) return null;
            foreach (XmlElement effNode in list)
            {
                var effinfo = LoadNativeEffectInformation(effNode);
                effects.Add(effinfo);
            }

            return effects;

        }

        private static IEnumerable<GroupEffectInformation> LoadGroupEffectInformations(XmlDocument xmldoc)
        {

            var effects = new List<GroupEffectInformation>();
            var list = xmldoc["动画数据"]["组数据列表"];
            if (list == null) return null;
            foreach (XmlElement effNode in list)
            {
                var effinfo = LoadGroupEffectInformation(effNode);
                effects.Add(effinfo);
            }

            return effects;
        }

        public static GroupEffectInformation LoadGroupEffectInformation(XmlElement effectNode, bool isreg = true)
        {
            var effect = new GroupEffectInformation();
            var 名称 = effectNode.GetAttribute("名称");
            var 注释 = effectNode.GetAttribute("描述");
            var 标签 = effectNode.GetAttribute("标签").Split(',');

            effect.Name = 名称;
            effect.Note = 注释;
            effect.Tags = 标签;
            effect.EffectInformationList = new List<EffectInformation>();

            if (isreg == true)
            {
                foreach (var tagName in 标签)
                {
                    var tagName2 = tagName.Trim();
                    if (tagName.Length == 0)
                        tagName2 = "默认标签";
                    if (!TagDictionary.ContainsKey(tagName2))
                    {
                        TagDictionary.Add(tagName2, new Tag()
                        {
                            Name = tagName2,
                            AnimEffect = new NativeAnimEffect(animEffect: PPT.MsoAnimEffect.msoAnimEffectCustom),
                            EffectInformationList = new List<EffectInformation>()
                        });
                    }

                    TagDictionary[tagName2].EffectInformationList.Add(effect);
                }
            }


            foreach (XmlElement xmlnode in effectNode.ChildNodes)
            {
                if (xmlnode.Name == "原生动画效果")
                {
                    effect.EffectInformationList.Add(LoadNativeEffectInformation(xmlnode, false));
                }
                else if (xmlnode.Name == "组动画效果")
                {
                    effect.EffectInformationList.Add(LoadGroupEffectInformation(xmlnode, false));
                }
                else if (xmlnode.Name == "动画效果")
                {
                    effect.EffectInformationList.Add(LoadArtificialEffectInformation(xmlnode, false));
                }
            }
            return effect;
        }
        public static NativeEffectInformation LoadNativeEffectInformation(XmlElement effectNode, bool isreg = true)
        {
            var effect = new NativeEffectInformation();
            var 名称 = effectNode.GetAttribute("名称");
            var 注释 = effectNode.GetAttribute("描述");
            var 标签 = effectNode.GetAttribute("标签").Split(',');
            var 文本模式 = effectNode.GetAttribute("文本模式");
            var 时长 = effectNode.GetAttribute("时长");
            var 延迟 = effectNode.GetAttribute("延迟");
            var 重复 = GetRepeat(effectNode.GetAttribute("重复"));
            var 平滑 = effectNode.GetAttribute("平滑").Split(',');
            var 平滑1 = 平滑[0];
            var 平滑2 = 平滑[1];
            var 弹跳 = effectNode.GetAttribute("弹跳");
            var 加速 = effectNode.GetAttribute("加速");
            var 减速 = effectNode.GetAttribute("减速");
            var 弹跳速度 = effectNode.GetAttribute("弹跳速度");
            var 自动返回 = effectNode.GetAttribute("自动返回");
            var 退出 = effectNode.GetAttribute("退出");
            var 类型 = effectNode.GetAttribute("类型");
            var 参数列表 = effectNode.GetAttribute("参数列表").Split(',');


            effect.Name = 名称;
            effect.Note = 注释;
            effect.Tags = 标签;

            if (isreg)
            {
                foreach (var tagName in 标签)
                {
                    var tagName2 = tagName.Trim();
                    if (tagName.Length == 0)
                        tagName2 = "默认标签";
                    if (!TagDictionary.ContainsKey(tagName2))
                    {
                        TagDictionary.Add(tagName2, new Tag()
                        {
                            Name = tagName2,
                            AnimEffect = new NativeAnimEffect(animEffect: PPT.MsoAnimEffect.msoAnimEffectCustom),
                            EffectInformationList = new List<EffectInformation>()
                        });
                    }

                    TagDictionary[tagName2].EffectInformationList.Add(effect);
                }
            }



            effect.AnimEffect = (PPT.MsoAnimEffect)Enum.Parse(typeof(PPT.MsoAnimEffect), 类型);
            effect.Arguments = 参数列表;

            if (GetValueAvaliable(退出))
                effect.Exit = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), 退出);

            if (GetValueAvaliable(文本模式))
                effect.TextUnitEffect = (PPT.MsoAnimTextUnitEffect)Enum.Parse(typeof(PPT.MsoAnimTextUnitEffect), 文本模式);
            if (GetValueAvaliable(时长))
                effect.Duration = float.Parse(时长);
            if (GetValueAvaliable(延迟))
                effect.Delay = float.Parse(延迟);
            if (GetValueAvaliable(重复))
                effect.Repeat = int.Parse(GetRepeat(重复));
            if (GetValueAvaliable(平滑1))
                effect.SmoothStart = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), 平滑1);
            if (GetValueAvaliable(平滑2))
                effect.SmoothEnd = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), 平滑2);
            if (GetValueAvaliable(弹跳))
                effect.BounceEnd = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), 弹跳);
            if (GetValueAvaliable(加速))
                effect.Accelerate = float.Parse(加速);
            if (GetValueAvaliable(减速))
                effect.Decelerate = float.Parse(减速);
            if (GetValueAvaliable(弹跳速度))
                effect.BounceEndIntensity = float.Parse(弹跳速度);
            if (GetValueAvaliable(自动返回))
                effect.AutoReverse = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), 自动返回);

            return effect;
        }
        public static ArtificialEffectInformation LoadArtificialEffectInformation(XmlElement effectNode, bool isreg = true)
        {
            var effect = new ArtificialEffectInformation() { Name = effectNode.GetAttribute("名称") };
            var 名称 = effectNode.GetAttribute("名称");
            var 注释 = effectNode.GetAttribute("描述");
            var 标签 = effectNode.GetAttribute("标签").Split(',');
            var 文本模式 = effectNode.GetAttribute("文本模式");
            var 时长 = effectNode.GetAttribute("时长");
            var 延迟 = effectNode.GetAttribute("延迟");
            var 重复 = GetRepeat(effectNode.GetAttribute("重复"));
            var 平滑 = effectNode.GetAttribute("平滑").Split(',');
            var 平滑1 = 平滑[0];
            var 平滑2 = 平滑[1];
            var 弹跳 = effectNode.GetAttribute("弹跳");
            var 加速 = effectNode.GetAttribute("加速");
            var 减速 = effectNode.GetAttribute("减速");
            var 弹跳速度 = effectNode.GetAttribute("弹跳速度");
            var 自动返回 = effectNode.GetAttribute("自动返回");

            effect.Name = 名称;
            effect.Note = 注释;
            effect.Tags = 标签;

            if (isreg)
            {
                foreach (var tagName in 标签)
                {
                    var tagName2 = tagName.Trim();
                    if (tagName.Length == 0)
                        tagName2 = "默认标签";
                    if (!TagDictionary.ContainsKey(tagName2))
                    {
                        TagDictionary.Add(tagName2, new Tag()
                        {
                            Name = tagName2,
                            AnimEffect = new NativeAnimEffect(animEffect: PPT.MsoAnimEffect.msoAnimEffectCustom),
                            EffectInformationList = new List<EffectInformation>()
                        });
                    }

                    TagDictionary[tagName2].EffectInformationList.Add(effect);
                }
            }



            if (GetValueAvaliable(文本模式))
                effect.TextUnitEffect = (PPT.MsoAnimTextUnitEffect)Enum.Parse(typeof(PPT.MsoAnimTextUnitEffect), 文本模式);
            if (GetValueAvaliable(时长))
                effect.Duration = float.Parse(时长);
            if (GetValueAvaliable(延迟))
                effect.Delay = float.Parse(延迟);
            if (GetValueAvaliable(重复))
                effect.Repeat = int.Parse(GetRepeat(重复));
            if (GetValueAvaliable(平滑1))
                effect.SmoothStart = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), 平滑1);
            if (GetValueAvaliable(平滑2))
                effect.SmoothEnd = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), 平滑2);
            if (GetValueAvaliable(弹跳))
                effect.BounceEnd = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), 弹跳);
            if (GetValueAvaliable(加速))
                effect.Accelerate = float.Parse(加速);
            if (GetValueAvaliable(减速))
                effect.Decelerate = float.Parse(减速);
            if (GetValueAvaliable(弹跳速度))
                effect.BounceEndIntensity = float.Parse(弹跳速度);
            if (GetValueAvaliable(自动返回))
                effect.AutoReverse = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), 自动返回);

            effect.BehaviorInformationList = new List<BehaviorInformation>();

            foreach (var behaviorNode in effectNode.OfType<XmlElement>())
            {
                effect.BehaviorInformationList.Add(LoadBehaviorInformation(behaviorNode));
            }

            return effect;

        }

        private static BehaviorInformation LoadBehaviorInformation(XmlElement behaviorNode)
        {
            BehaviorInformation behavior;
            var b名称 = behaviorNode.Name;
            var b注释 = behaviorNode.GetAttribute("注释");
            var b时长 = behaviorNode.GetAttribute("时长");
            var b延迟 = behaviorNode.GetAttribute("延迟");
            var b重复 = GetRepeat(behaviorNode.GetAttribute("重复"));
            var b平滑 = behaviorNode.GetAttribute("平滑").Split(',');
            var b平滑1 = b平滑[0];
            var b平滑2 = b平滑[1];
            var b弹跳 = behaviorNode.GetAttribute("弹跳");
            var b加速 = behaviorNode.GetAttribute("加速");
            var b减速 = behaviorNode.GetAttribute("减速");
            var b弹跳速度 = behaviorNode.GetAttribute("弹跳速度");
            var b自动返回 = behaviorNode.GetAttribute("自动返回");

            // var bhvType = typedic2[b名称];


            switch (b名称)
            {
                case "设置":
                    {
                        var set属性类型 = behaviorNode.GetAttribute("属性类型");
                        var set属性值 = behaviorNode.GetAttribute("终点");
                        var setbhv = new SetBehaviorInformation();

                        var prop = propdic2[set属性类型];
                        setbhv.Property = prop;

                        if (GetValueAvaliable(set属性值))
                        {
                            if (prop == PPT.MsoAnimProperty.msoAnimVisibility)
                                setbhv.Value = int.Parse(set属性值);
                            else if (prop == PPT.MsoAnimProperty.msoAnimColor)
                                setbhv.Value = int.Parse(set属性值);
                            else if (prop == PPT.MsoAnimProperty.msoAnimTextBulletFontName)
                                setbhv.Value = set属性值;
                            else
                                setbhv.Value = float.Parse(set属性值);
                        }


                        behavior = setbhv;

                    }

                    break;
                case "属性":
                    {
                        var prop属性类型 = behaviorNode.GetAttribute("属性类型");
                        var prop属性值起点 = behaviorNode.GetAttribute("起点");
                        var prop属性值终点 = behaviorNode.GetAttribute("终点");
                        var propbhv = new PropertyBehaviorInformation();
                        var prop = propdic2[prop属性类型];
                        propbhv.Property = prop;

                        if (GetValueAvaliable(prop属性值起点))
                        {
                            if (prop == PPT.MsoAnimProperty.msoAnimVisibility)
                                propbhv.From = int.Parse(prop属性值起点);
                            else if (prop == PPT.MsoAnimProperty.msoAnimColor)
                                propbhv.From = int.Parse(prop属性值起点);
                            else if (prop == PPT.MsoAnimProperty.msoAnimTextBulletFontName)
                                propbhv.From = prop属性值起点;
                            else
                                propbhv.From = float.Parse(prop属性值起点);
                        }

                        if (GetValueAvaliable(prop属性值终点))
                        {
                            if (prop == PPT.MsoAnimProperty.msoAnimVisibility)
                                propbhv.To = int.Parse(prop属性值终点);
                            else if (prop == PPT.MsoAnimProperty.msoAnimColor)
                                propbhv.To = int.Parse(prop属性值终点);
                            else if (prop == PPT.MsoAnimProperty.msoAnimTextBulletFontName)
                                propbhv.To = prop属性值终点;
                            else
                                propbhv.To = float.Parse(prop属性值终点);
                        }

                        propbhv.KeyPoints = new List<KeyPointInformation>();

                        foreach (var point in behaviorNode.OfType<XmlElement>())
                        {
                            var keypoint = new KeyPointInformation();
                            var pt注释 = point.GetAttribute("注释");
                            var pt时间 = point.GetAttribute("时间");
                            var pt值 = point.GetAttribute("值");
                            var pt表达式 = point.GetAttribute("表达式");

                            keypoint.Note = pt注释;
                            keypoint.Time = float.Parse(pt时间);

                            if (prop == PPT.MsoAnimProperty.msoAnimVisibility)
                                keypoint.Value = bool.Parse(pt值);
                            else
                                keypoint.Value = pt值;

                            keypoint.Formula = pt表达式;
                            propbhv.KeyPoints.Add(keypoint);
                        }
                        behavior = propbhv;
                    }

                    break;
                case "颜色":
                    {
                        var clr起点 = behaviorNode.GetAttribute("起点");
                        var clr终点 = behaviorNode.GetAttribute("终点");
                        var clr变化 = behaviorNode.GetAttribute("变化");
                        var clrbhv = new ColorBehaviorInformation();
                        if (GetValueAvaliable(clr起点))
                            clrbhv.From = int.Parse(clr起点);
                        if (GetValueAvaliable(clr终点))
                            clrbhv.To = int.Parse(clr终点);
                        if (GetValueAvaliable(clr变化))
                            clrbhv.By = int.Parse(clr变化);
                        behavior = clrbhv;
                    }
                    break;
                case "比例":
                    {
                        var sc起点 = behaviorNode.GetAttribute("起点").Split(',');
                        var sc终点 = behaviorNode.GetAttribute("终点").Split(',');
                        var sc变化 = behaviorNode.GetAttribute("变化").Split(',');
                        var scbhv = new ScaleBehaviorInformation();
                        if (GetValueAvaliable(sc起点[0]))
                            scbhv.FromX = float.Parse(sc起点[0]);
                        if (GetValueAvaliable(sc起点[1]))
                            scbhv.FromY = float.Parse(sc起点[1]);
                        if (GetValueAvaliable(sc终点[0]))
                            scbhv.ToX = float.Parse(sc终点[0]);
                        if (GetValueAvaliable(sc终点[1]))
                            scbhv.ToY = float.Parse(sc终点[1]);
                        if (GetValueAvaliable(sc变化[0]))
                            scbhv.ByX = float.Parse(sc变化[0]);
                        if (GetValueAvaliable(sc变化[1]))
                            scbhv.ByY = float.Parse(sc变化[1]);
                        behavior = scbhv;
                    }

                    break;
                case "旋转":
                    {
                        var rot起点 = behaviorNode.GetAttribute("起点");
                        var rot终点 = behaviorNode.GetAttribute("终点");
                        var rot变化 = behaviorNode.GetAttribute("变化");
                        var rotbhv = new RotationBehaviorInformation();
                        if (GetValueAvaliable(rot起点))
                            rotbhv.From = float.Parse(rot起点);
                        if (GetValueAvaliable(rot终点))
                            rotbhv.To = float.Parse(rot终点);
                        if (GetValueAvaliable(rot变化))
                            rotbhv.By = float.Parse(rot变化);
                        behavior = rotbhv;
                    }


                    break;
                case "滤镜":
                    {
                        var ft主滤镜 = behaviorNode.GetAttribute("主滤镜");
                        var ft子滤镜 = behaviorNode.GetAttribute("子滤镜");
                        var ft反转 = behaviorNode.GetAttribute("反转");
                        var ftbhv = new FilterBehaviorInformation();

                        if (GetValueAvaliable(ft反转))
                            ftbhv.Reveal = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), ft反转);

                        ftbhv.MainFilter = (PPT.MsoAnimFilterEffectType)Enum.Parse(typeof(PPT.MsoAnimFilterEffectType), ft主滤镜);

                        if (ft子滤镜 != "none" && ft子滤镜.Length != 0)
                            ftbhv.SubFilter = (PPT.MsoAnimFilterEffectSubtype)Enum.Parse(typeof(PPT.MsoAnimFilterEffectSubtype), ft子滤镜);
                        behavior = ftbhv; ;
                    }

                    break;
                case "移动":
                    {
                        var mo起点 = behaviorNode.GetAttribute("起点").Split(',');
                        var mo终点 = behaviorNode.GetAttribute("终点").Split(',');
                        var mo变化 = behaviorNode.GetAttribute("变化").Split(',');
                        var mo路径 = behaviorNode.GetAttribute("路径");
                        var mobhv = new MotionBehaviorInformation();
                        if (GetValueAvaliable(mo起点[1]))
                            mobhv.FromX = float.Parse(mo起点[0]);
                        if (GetValueAvaliable(mo起点[1]))
                            mobhv.FromX = float.Parse(mo起点[1]);
                        if (GetValueAvaliable(mo终点[1]))
                            mobhv.ToX = float.Parse(mo终点[0]);
                        if (GetValueAvaliable(mo终点[1]))
                            mobhv.ToY = float.Parse(mo终点[1]);
                        if (GetValueAvaliable(mo变化[1]))
                            mobhv.ByX = float.Parse(mo变化[0]);
                        if (GetValueAvaliable(mo变化[1]))
                            mobhv.ByY = float.Parse(mo变化[1]);
                        if (GetValueAvaliable(mo路径))
                            mobhv.Path = mo路径;

                        behavior = mobhv; ;
                    }

                    break;
                default:
                    return null;
            }

            behavior.Note = b注释;
            if (GetValueAvaliable(b时长))
                behavior.Duration = float.Parse(b时长);
            if (GetValueAvaliable(b延迟))
                behavior.Delay = float.Parse(b延迟);
            if (GetValueAvaliable(b重复))
                behavior.Repeat = int.Parse(GetRepeat(b重复));
            if (GetValueAvaliable(b平滑1))
                behavior.SmoothStart = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), b平滑1);
            if (GetValueAvaliable(b平滑2))
                behavior.SmoothEnd = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), b平滑2);
            if (GetValueAvaliable(b弹跳))
                behavior.BounceEnd = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), b弹跳);
            if (GetValueAvaliable(b加速))
                behavior.Accelerate = float.Parse(b加速);
            if (GetValueAvaliable(b减速))
                behavior.Decelerate = float.Parse(b减速);
            if (GetValueAvaliable(b弹跳速度))
                behavior.BounceEndIntensity = float.Parse(b弹跳速度);
            if (GetValueAvaliable(b自动返回))
                behavior.AutoReverse = (Office.MsoTriState)Enum.Parse(typeof(Office.MsoTriState), b自动返回);

            return behavior; ;

        }


    }
}
